﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using Agent;
using System.IO;

public partial class Member_Agent_SincereAgentList : nspBase.MemberBasePge
{
    string verify = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckCookies())
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        else
            Response.Redirect("~/login/login.aspx");
    }

    public string GetImagePath(string Path)
    {
        int k = 0;
        string s = "";
        string EPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
        for (int i = 0; i < Path.Length; i++)
        {
            if (k != 2)
            {
                if (Path[i].Equals('/'))
                {
                    k++;
                }
            }
            else
            {
                s += Path[i];
            }
        }
        if (File.Exists(EPath+s))
        {
            return Path;
        }
        else
        {
            return "../../Images/System/wutu.gif";
        }
    }

    private void Bind()
    {
        int Userid = int.Parse(GetCookie("UserID"));
        if (Userid > 0)
        {
            int PageIndex = 0;
            if (HttpContext.Current.Request.QueryString["page"] != null)
                PageIndex = Convert.ToInt32(Request.QueryString["Page"].ToString());
            if (PageIndex <= 0) PageIndex = 1;
            string strWhere = " UserID=" + Userid;
            if (verify == "")
            {
                verify = "1";
            }
            if (Request.QueryString["Verify"] != null && Request.QueryString["Verify"] != "")
            {

                if (Request.QueryString["Verify"] == "4")//过期信息
                {
                    strWhere += " and (datediff(day,AddDate,getdate())>Validity)";
                }
                else if (Request.QueryString["Verify"] == "3")//未审核信息
                {
                    strWhere += " and Verify =";
                    strWhere += Request.QueryString["Verify"];
                }
                else if (Request.QueryString["Verify"] == "2")//审核信息
                {
                    strWhere += " and Verify =";
                    strWhere += Request.QueryString["Verify"];
                }
                else //已发布上网
                {
                    strWhere += " and (datediff(day,AddDate,getdate())<Validity) and Verify =";
                    strWhere += Request.QueryString["Verify"];
                }
                verify = Request.QueryString["Verify"];
            }
            else //默认进入已发布上网
            {
                strWhere += " and Verify =1 and (datediff(day,AddDate,getdate())<Validity)";

            }
            DataTable Lists = PageList.GetDataTable(strWhere, "W_SincereAgent", 1, "AddDate", "*", 10, PageIndex, 0);
            dlstSincereAgent.DataSource = Lists.DefaultView;
            dlstSincereAgent.DataBind();
            this.Pagin.Text = PageList.GoToPager(PageIndex, 10, "SincereAgentList.aspx?Verify=" + verify + "&page", strWhere, "W_SincereAgent");
            btnDelete.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
            SetColor();
        }
        else
            Response.Redirect("../login/login.aspx");
    }
    /// <summary>
    /// 设置颜色
    /// </summary>
    private void SetColor()
    {
        if (Request.QueryString["Verify"] != null)
        {
            if (Request.QueryString["Verify"] == "3")
                this.menu2.Attributes.Add("class", "MenuLiCheck");
            else if (Request.QueryString["Verify"] == "2")
                this.menu3.Attributes.Add("class", "MenuLiCheck");
            else if (Request.QueryString["Verify"] == "4")
                this.menu4.Attributes.Add("class", "MenuLiCheck");
            else
                this.menu1.Attributes.Add("class", "MenuLiCheck");
        }
        else
            this.menu1.Attributes.Add("class", "MenuLiCheck");
    }
    public string GetShortDate(string dateStr,string strday)
    {
        if (dateStr != string.Empty && strday!=string.Empty)
            return Convert.ToDateTime(dateStr).AddDays(Int32.Parse(strday)).ToShortDateString();
        else
            return String.Empty;
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= dlstSincereAgent.Items.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)dlstSincereAgent.Items[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = Convert.ToInt32(dlstSincereAgent.DataKeys[i]);
                ISincereAgent RUser = new RSincereAgent();
                int m = RUser.Delete(id);
            }
        }
        Bind();
    }
}
